
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

class MyThreadPool{
    private BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();

    public void submit(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }
    MyThreadPool(int n){
        //创建n个线程，如果没有任务，则阻塞等待
        for(int i = 0; i < n; i++){
            Thread t = new Thread(() -> {
                try {
                    //如果没有任务，让线程阻塞等待
                    Runnable runnable = queue.take();
                    runnable.run();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
            t.start();
        }
    }
}

public class Demo2 {
    public static void main(String[] args) {

    }
}
